package com.sgave.blog.service.Impl;

import com.sgave.blog.mapper.BlogMapper;
import com.sgave.blog.model.Blog;
import com.sgave.blog.service.BlogService;
import com.sgave.blog.vo.BlogVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author fly
 * @date 2024/1/9 18:14
 */
@Service
public class BlogServiceImpl implements BlogService {

    @Resource
    private BlogMapper blogMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addBlog(Blog blog) {
        return blogMapper.addBlog(blog);
    }

    @Override
    public BlogVo selectById(Integer id) {
        blogMapper.updateReadCount(id);
        return blogMapper.selectById(id);
    }

    @Override
    public List<BlogVo> selectAll() {
        return blogMapper.selectAll();
    }

    @Override
    public List<BlogVo> selectByParam(String param, Integer labelId) {
        return blogMapper.selectByParam(param, labelId);
    }

    @Override
    public List<BlogVo> selectHotNews(Integer num) {
        return blogMapper.selectHotNews(num);
    }
}
